﻿package mortal.game.view.playerSystem
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.palyer.*;
    import mortal.game.view.palyer.data.*;
    import mortal.game.view.palyer.util.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class PlayerController extends PlayerBaseController
    {
        private var _playerModule:PlayerInfoModule;

        public function PlayerController()
        {
            return;
        }// end function

        override protected function initView() : GSprite
        {
            if (this._playerModule == null)
            {
                this._playerModule = new PlayerInfoModule(GameController.playerSystem.view as Window);
            }
            return this._playerModule;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(EGateCommand._ECmdGatePlayerSuitUpdate, this.playerSuitInfoHandler);
            NetDispatcher.addCmdListener(ServerCommand.FashionHideStateUpdate, this.onFashionHideStateUpdate);
            Dispatcher.addEventListener(EventName.PlayerWinOpen, this.playerWinOpen);
            return;
        }// end function

        private function playerSuitInfoHandler(param1:MessageBlock) : void
        {
            var _loc_2:* = param1.messageBase as SPlayerSuitInfo;
            Cache.instance.role.updateSuitInfos(_loc_2);
            return;
        }// end function

        override public function addWinShowEvent() : void
        {
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateComBat, this.updateComBat);
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateLife, this.updateLife);
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateMana, this.updateMana);
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateGuild, this.updateGuild);
            Cache.instance.role.roleEntityInfo.addEventListener(EntityInfoEventName.UpdateLevel, this.updateLevel);
            NetDispatcher.addCmdListener(ServerCommand.RoleFightAttributeChange, this.updateAttributes);
            NetDispatcher.addCmdListener(ServerCommand.ExpUpdate, this.updateExp);
            NetDispatcher.addCmdListener(ServerCommand.updateEquipMent, this.updateEquipByType);
            NetDispatcher.addCmdListener(ServerCommand.VipLevelUp, this.updateVip);
            NetDispatcher.addCmdListener(ServerCommand.RoleHalidomUpdate, this.updateHalidomEquipByType);
            NetDispatcher.addCmdListener(ServerCommand.MedalAdd, this.medalAdd);
            Dispatcher.addEventListener(EventName.GetOffEquip, this.equipHandler);
            Dispatcher.addEventListener(EventName.TitleSwitchToTitle, this.switchToTitlePanel);
            Dispatcher.addEventListener(EventName.TitleUpdate, this.updateTitleHandler);
            return;
        }// end function

        override public function removeWinShowEvent() : void
        {
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateComBat, this.updateComBat);
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateLife, this.updateLife);
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateMana, this.updateMana);
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateGuild, this.updateGuild);
            Cache.instance.role.roleEntityInfo.removeEventListener(EntityInfoEventName.UpdateLevel, this.updateLevel);
            NetDispatcher.removeCmdListener(ServerCommand.RoleFightAttributeChange, this.updateAttributes);
            NetDispatcher.removeCmdListener(ServerCommand.ExpUpdate, this.updateExp);
            NetDispatcher.removeCmdListener(ServerCommand.updateEquipMent, this.updateEquipByType);
            NetDispatcher.removeCmdListener(ServerCommand.VipLevelUp, this.updateVip);
            NetDispatcher.removeCmdListener(ServerCommand.RoleHalidomUpdate, this.updateHalidomEquipByType);
            NetDispatcher.removeCmdListener(ServerCommand.MedalAdd, this.medalAdd);
            Dispatcher.removeEventListener(EventName.GetOffEquip, this.equipHandler);
            Dispatcher.removeEventListener(EventName.TitleSwitchToTitle, this.switchToTitlePanel);
            Dispatcher.removeEventListener(EventName.TitleUpdate, this.updateTitleHandler);
            return;
        }// end function

        private function playerWinOpen(param1:Object) : void
        {
            if (this.isViewShow)
            {
                GameController.playerSystem.view.hide();
            }
            else
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, PlayerConst.TabType_Role));
            }
            return;
        }// end function

        private function updateAttributes(param1:Object = null) : void
        {
            if (this._playerModule == null)
            {
                return;
            }
            if (Cache.instance.role.fightAttribute)
            {
                this._playerModule.updateAllInfo(param1 as SFightAttribute);
            }
            return;
        }// end function

        private function updateLife(event:Event) : void
        {
            this._playerModule.updateLife();
            return;
        }// end function

        private function updateMana(event:Event) : void
        {
            this._playerModule.updateMana();
            return;
        }// end function

        private function updateExp(param1:Object) : void
        {
            this._playerModule.updateExp(param1 as int);
            return;
        }// end function

        private function updateEquipByType(param1:int) : void
        {
            this._playerModule.updateEquipByType(param1);
            return;
        }// end function

        private function updateHalidomEquipByType(param1:int) : void
        {
            this._playerModule.updateHalidomEquipByType(param1);
            return;
        }// end function

        private function updateAllEquip() : void
        {
            this._playerModule.updateAllEquip();
            return;
        }// end function

        private function updateLevel(event:Event) : void
        {
            return;
        }// end function

        private function equipHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            if (Cache.instance.pack.backPackCache.isPackFull(_loc_2.itemInfo.code, 1))
            {
                return MsgManager.showRollTipsMsg(Language.getString(35524), MsgRollTipsType.msgRollTips3);
            }
            GameProxy.equip.dress(null, _loc_2.serverData.uid);
            return;
        }// end function

        private function updateComBat(event:Event) : void
        {
            this._playerModule.updateComBat();
            return;
        }// end function

        private function updateGuild(event:Event) : void
        {
            this._playerModule.updateGuild();
            return;
        }// end function

        private function updateVip(param1:Object) : void
        {
            this._playerModule.updateVip();
            return;
        }// end function

        private function getAllTitleHandler(param1:Object) : void
        {
            Cache.instance.title.initTitleData(param1.titles);
            return;
        }// end function

        private function updateTitleHandler(param1:Object) : void
        {
            if (this._playerModule)
            {
                this._playerModule.updateTitle();
            }
            return;
        }// end function

        private function switchToTitlePanel(event:DataEvent) : void
        {
            return;
        }// end function

        private function activeTitleHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            GameProxy.titleProxy.activeTitle(_loc_2.serverData.uid);
            return;
        }// end function

        private function updateTitleHideStatus(param1:Object) : void
        {
            if (ClientSetting.local.getIsDone(IsDoneType.HideTitle))
            {
                GameProxy.titleProxy.hideTitle(0);
            }
            return;
        }// end function

        private function resetTitleHideStatus(param1:Object) : void
        {
            if (ClientSetting.local.getIsDone(IsDoneType.HideTitle))
            {
                ClientSetting.local.setIsDone(false, IsDoneType.HideTitle);
            }
            return;
        }// end function

        private function onFashionHideStateUpdate(param1:Object) : void
        {
            return;
        }// end function

        private function onUseFashionSkillBook(event:DataEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:FashionAdvanceData = null;
            var _loc_6:ItemData = null;
            var _loc_2:* = event.data;
            if (_loc_2)
            {
                _loc_3 = _loc_2.skillType as int;
                _loc_4 = FashionUtil.getFashionTypeBySkillType(_loc_3);
                _loc_5 = Cache.instance.fashion.getFashionInfo(_loc_4);
                if (_loc_5.advanceInfo == null)
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(35525, FashionUtil.getFashionNameByType(_loc_4)));
                    return;
                }
                _loc_6 = _loc_2.itemData;
                GameProxy.packProxy.useItem(_loc_6.uid, _loc_6.itemCode);
            }
            return;
        }// end function

        private function medalAdd(param1:Object) : void
        {
            this._playerModule.updateMedal();
            return;
        }// end function

    }
}
